*Module 2

use cses2orig, clear

*-------------------------------------------------------------------------------
* 1. Recoding of variables
*-------------------------------------------------------------------------------

tab B1004
gen cntelec=B1004
label var cntelec "Country-election"
tab cntelec

tab B1006_NAM
gen cntry=B1006_NAM
lab var cntry "Country"
tab cntry

tab B2005
recode B2005 2=0 1=1 7/9=., gen (unionm)
label var unionm "Union membership" 
lab def unionm 0 "Non-member" 1 "Member"
lab val unionm unionm
tab unionm

tab B2001
recode B2001 998/999=., gen (age)
label var age "Age" 
tab age

tab B2002
recode B2002 1=0 2=1 9=., gen (gender)
label var gender "Gender" 
lab def gender 0 "Male" 1 "Female"
lab val gender gender
tab gender

tab B2030
by cntry, sort: tab B2030
recode B2030 1=1 2=2 3=3 4=4 8/9=., gen (locat)
label var locat "Location, rural-urban" 
lab def locat 1 "Village" 2 "Small/middle city" 3 "Suburbs" 4 "Large city"
lab val locat locat
tab locat

tab B2003
recode B2003 1/7=0 8=1 97/99=. , gen (educ)
label var educ "Education, 2 cat" 
lab def educ 0 "Non-tertiary education" 1 "Tertiary education" 
lab val educ educ
tab educ

*-------------------------------------------------------------------------------
* 2. Social class
*-------------------------------------------------------------------------------

* 2.1 Recode occupation variable (clasdtprep), recode employment status (status)

recode B2011 96/99=. 01=3 11/13=6 21=5 22/24=4 31=5 32/33=4 34=6 41/43=3 50=1 51/53=1 61/62=2 71/84=2 91=1 92/94=2, gen (clasdtprep)
label var clasdtprep "Social class preparation, detailed" 
lab def clasdtprep 1 "Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers"
lab val clasdtprep clasdtprep
tab clasdtprep

recode B2012 1/2=1 3/4=2 5/6=. 7/9=., gen (status)
replace status=1 if (B2012==5 & cntry=="New Zealand") | (B2012==5 & cntry=="Spain") 
label var status "Employment status" 
lab def status 1 "Employed" 2"Self-employed"
lab val status status
tab status

* 2.2 Combine occupation and status

gen clasdt=.
replace clasdt=1 if clasdtprep==1 & status==1 /*Serv + employed = serv workers*/
replace clasdt=2 if clasdtprep==2 & status==1 /*Prod + employed = prod workers*/
replace clasdt=3 if clasdtprep==3 & status==1 /*Clerks + employed = clerks*/
replace clasdt=4 if clasdtprep==4 & status==1 /*Socio + employed = socio-cult prof*/
replace clasdt=5 if clasdtprep==5 & status==1 /*Tech + employed = tech prof*/
replace clasdt=6 if clasdtprep==6 & status==1 /*Manag + employed = managers*/
replace clasdt=7 if (clasdtprep==1 & status==2) | (clasdtprep==2 & status==2) | (clasdtprep==3 & status==2) /*working class occupation + self-employed=small business*/
replace clasdt=8 if (clasdtprep==4 & status==2) | (clasdtprep==5 & status==2) | (clasdtprep==6 & status==2) /*middle class occupation + self-employed=large empl/professional*/
label var clasdt "Social class, detailed" 
lab def clasdt 1"Service work" 2 "Prod work" 3 "Clerks" 4 "Socio-cultural" 5 "Technical" 6 "Managers" 7"Small business" 8"Large employers and self-employed prof"
lab val clasdt clasdt
tab clasdt


*-------------------------------------------------------------------------------
* 3. Voting behaviour - current election
*-------------------------------------------------------------------------------

* 3.1 Creation of party5 variable from B3006_1 for all countries

recode B3006_1 (94/99=200), gen (party5)

replace party5=3 if inlist(B3006_1, 7) & cntelec=="AUS_2004" /*Australia*/
replace party5=2 if inlist(B3006_1, 3) & cntelec=="AUS_2004" /*Australia*/
replace party5=10 if inlist(B3006_1, 4) & cntelec=="AUS_2004" /*Australia*/
replace party5=0 if !inlist(B3006_1, 3,4,7) & !missing(party5) & party5!=200 & cntelec=="AUS_2004" 
tab party5 if cntelec=="AUS_2004"
tab B3006_1 if cntelec=="AUS_2004"

replace party5=3 if inlist(B3006_1, 6,9) & cntelec=="DNK_2001" /*Denmark*/
replace party5=2 if inlist(B3006_1, 1) & cntelec=="DNK_2001" /*Denmark*/
replace party5=10 if inlist(B3006_1, 10) & cntelec=="DNK_2001" /*Denmark*/
replace party5=11 if inlist(B3006_1, 5) & cntelec=="DNK_2001" /*Denmark*/
replace party5=0 if !inlist(B3006_1, 1,5,10,6,9) & !missing(party5) & party5!=200 & cntelec=="DNK_2001" 
tab party5 if cntelec=="DNK_2001"
tab B3006_1 if cntelec=="DNK_2001"

replace party5=3 if inlist(B3006_1, 8) & cntelec=="FIN_2003" /*Finland*/
replace party5=2 if inlist(B3006_1, 1) & cntelec=="FIN_2003" /*Finland*/
replace party5=10 if inlist(B3006_1, 6) & cntelec=="FIN_2003" /*Finland*/
replace party5=11 if inlist(B3006_1, 4) & cntelec=="FIN_2003" /*Finland*/
replace party5=0 if !inlist(B3006_1, 1,4,6,8) & !missing(party5) & party5!=200 & cntelec=="FIN_2003" 
tab party5 if cntelec=="FIN_2003"
tab B3006_1 if cntelec=="FIN_2003"

replace party5=3 if inlist(B3006_1, 7,10,11) & cntelec=="DEU12002" /*Germany*/
replace party5=2 if inlist(B3006_1, 1) & cntelec=="DEU12002" /*Germany*/
replace party5=10 if inlist(B3006_1, 4) & cntelec=="DEU12002" /*Germany*/
replace party5=11 if inlist(B3006_1, 6) & cntelec=="DEU12002" /*Germany*/
replace party5=0 if !inlist(B3006_1, 1,4,6,7,10,11) & !missing(party5) & party5!=200 & cntelec=="DEU12002" 
tab party5 if cntelec=="DEU12002"
tab B3006_1 if cntelec=="DEU12002"

replace party5=2 if inlist(B3006_1, 1) & cntelec=="GBR_2005" /*Great-Britain*/
replace party5=0 if !inlist(B3006_1, 1) & !missing(party5) & party5!=200 & cntelec=="GBR_2005" 
tab party5 if cntelec=="GBR_2005"
tab B3006_1 if cntelec=="GBR_2005"

replace party5=2 if inlist(B3006_1, 1) & cntelec=="ISL_2003" /*Iceland*/
replace party5=10 if inlist(B3006_1, 8) & cntelec=="ISL_2003" /*Iceland*/
replace party5=11 if inlist(B3006_1, 4) & cntelec=="ISL_2003" /*Iceland*/
replace party5=0 if !inlist(B3006_1, 1,4,8) & !missing(party5) & party5!=200 & cntelec=="ISL_2003" 
tab party5 if cntelec=="ISL_2003"
tab B3006_1 if cntelec=="ISL_2003"

replace party5=2 if inlist(B3006_1, 4) & cntelec=="IRL_2002" /*Ireland*/
replace party5=10 if inlist(B3006_1, 3) & cntelec=="IRL_2002" /*Ireland*/
replace party5=11 if inlist(B3006_1, 6) & cntelec=="IRL_2002" /*Ireland*/
replace party5=0 if !inlist(B3006_1, 3,4,6) & !missing(party5) & party5!=200 & cntelec=="IRL_2002" 
tab party5 if cntelec=="IRL_2002"
tab B3006_1 if cntelec=="IRL_2002"

replace party5=3 if inlist(B3006_1, 9) & cntelec=="NLD_2002" /*Netherlands*/
replace party5=2 if inlist(B3006_1, 1) & cntelec=="NLD_2002" /*Netherlands*/
replace party5=10 if inlist(B3006_1, 5) & cntelec=="NLD_2002" /*Netherlands*/
replace party5=11 if inlist(B3006_1, 10) & cntelec=="NLD_2002" /*Netherlands*/
replace party5=0 if !inlist(B3006_1, 1,5,10,9) & !missing(party5) & party5!=200 & cntelec=="NLD_2002" 
tab party5 if cntelec=="NLD_2002"
tab B3006_1 if cntelec=="NLD_2002"

replace party5=3 if inlist(B3006_1, 3) & cntelec=="NZL_2002" /*New Zealand*/
replace party5=2 if inlist(B3006_1, 1) & cntelec=="NZL_2002" /*New Zealand*/
replace party5=10 if inlist(B3006_1, 5) & cntelec=="NZL_2002" /*New Zealand*/
replace party5=11 if inlist(B3006_1, 7,8) & cntelec=="NZL_2002" /*New Zealand*/
replace party5=0 if !inlist(B3006_1, 1,5,7,8,3) & !missing(party5) & party5!=200 & cntelec=="NZL_2002" 
tab party5 if cntelec=="NZL_2002"
tab B3006_1 if cntelec=="NZL_2002"

replace party5=3 if inlist(B3006_1, 9) & cntelec=="NOR_2001" /*Norway*/
replace party5=2 if inlist(B3006_1, 3) & cntelec=="NOR_2001" /*Norway*/
replace party5=10 if inlist(B3006_1, 1) & cntelec=="NOR_2001" /*Norway*/
replace party5=11 if inlist(B3006_1, 2) & cntelec=="NOR_2001" /*Norway*/
replace party5=0 if !inlist(B3006_1, 1,2,3,9) & !missing(party5) & party5!=200 & cntelec=="NOR_2001" 
tab party5 if cntelec=="NOR_2001"
tab B3006_1 if cntelec=="NOR_2001"

replace party5=2 if inlist(B3006_1, 2) & cntelec=="ESP_2004" /*Spain*/
replace party5=10 if inlist(B3006_1, 15,18) & cntelec=="ESP_2004" /*Spain*/
replace party5=11 if inlist(B3006_1, 3) & cntelec=="ESP_2004" /*Spain*/
replace party5=0 if !inlist(B3006_1, 2,3,15,18) & !missing(party5) & party5!=200 & cntelec=="ESP_2004" 
tab party5 if cntelec=="ESP_2004"
tab B3006_1 if cntelec=="ESP_2004"

replace party5=2 if inlist(B3006_1, 2) & cntelec=="SWE_2002" /*Sweden*/
replace party5=10 if inlist(B3006_1, 7) & cntelec=="SWE_2002" /*Sweden*/
replace party5=11 if inlist(B3006_1, 1) & cntelec=="SWE_2002" /*Sweden*/
replace party5=0 if !inlist(B3006_1, 1,2,7) & !missing(party5) & party5!=200 & cntelec=="SWE_2002" 
tab party5 if cntelec=="SWE_2002"
tab B3006_1 if cntelec=="SWE_2002"

label var party5 "Party choice, detailed"
lab def party5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5 party5
tab party5

* 3.2 Turnout

tab B3004_1
recode B3004_1 1=1 2=2 4/9=3, gen (turnout) 
label var turnout "Turnout" 
lab def turnout 1 "Voted" 2 "Not voted" 3 "Other"
lab val turnout turnout
tab turnout


* 3.3 Merge party and turnout: new variable party5abs

gen party5abs=party5
replace party5abs=4 if turnout==2 /*turnout: add a fourth category*/ 
replace party5abs=6 if turnout==3 /*other answer on turnout: add a sixth category*/ 
label var party5abs "Party choice with abstainers, detailed"
lab def party5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val party5abs party5abs 
tab party5abs


*-------------------------------------------------------------------------------
* 4. Voting behaviour - previous election  
*-------------------------------------------------------------------------------

* 4.1 Creation of preparty5 variable from B3018_1 for all countries

recode B3018_1 (94/99=200), gen (preparty5)

replace preparty5=3 if inlist(B3018_1, 7) & cntelec=="AUS_2004" /*Australia*/
replace preparty5=2 if inlist(B3018_1, 3) & cntelec=="AUS_2004" /*Australia*/
replace preparty5=10 if inlist(B3018_1, 4) & cntelec=="AUS_2004" /*Australia*/
replace preparty5=0 if !inlist(B3018_1, 3,4,7) & !missing(preparty5) & preparty5!=200 & cntelec=="AUS_2004" 
tab preparty5 if cntelec=="AUS_2004"
tab B3018_1 if cntelec=="AUS_2004"

replace preparty5=3 if inlist(B3018_1, 6,9) & cntelec=="DNK_2001" /*Denmark*/
replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="DNK_2001" /*Denmark*/
replace preparty5=10 if inlist(B3018_1, 10) & cntelec=="DNK_2001" /*Denmark*/
replace preparty5=11 if inlist(B3018_1, 5) & cntelec=="DNK_2001" /*Denmark*/
replace preparty5=0 if !inlist(B3018_1, 1,5,10,6,9) & !missing(preparty5) & preparty5!=200 & cntelec=="DNK_2001" 
tab preparty5 if cntelec=="DNK_2001"
tab B3018_1 if cntelec=="DNK_2001"

replace preparty5=3 if inlist(B3018_1, 8) & cntelec=="FIN_2003" /*Finland*/
replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="FIN_2003" /*Finland*/
replace preparty5=10 if inlist(B3018_1, 6) & cntelec=="FIN_2003" /*Finland*/
replace preparty5=11 if inlist(B3018_1, 4) & cntelec=="FIN_2003" /*Finland*/
replace preparty5=0 if !inlist(B3018_1, 1,4,6,8) & !missing(preparty5) & preparty5!=200 & cntelec=="FIN_2003" 
tab preparty5 if cntelec=="FIN_2003"
tab B3018_1 if cntelec=="FIN_2003"

replace preparty5=3 if inlist(B3018_1, 7,10,11) & cntelec=="DEU12002" /*Germany*/
replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="DEU12002" /*Germany*/
replace preparty5=10 if inlist(B3018_1, 4) & cntelec=="DEU12002" /*Germany*/
replace preparty5=11 if inlist(B3018_1, 6) & cntelec=="DEU12002" /*Germany*/
replace preparty5=0 if !inlist(B3018_1, 1,4,6,7,10,11) & !missing(preparty5) & preparty5!=200 & cntelec=="DEU12002" 
tab preparty5 if cntelec=="DEU12002"
tab B3018_1 if cntelec=="DEU12002"

replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="GBR_2005" /*Great-Britain*/
replace preparty5=0 if !inlist(B3018_1, 1) & !missing(preparty5) & preparty5!=200 & cntelec=="GBR_2005" 
tab preparty5 if cntelec=="GBR_2005"
tab B3018_1 if cntelec=="GBR_2005"

replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="ISL_2003" /*Iceland*/
replace preparty5=10 if inlist(B3018_1, 8) & cntelec=="ISL_2003" /*Iceland*/
replace preparty5=11 if inlist(B3018_1, 4) & cntelec=="ISL_2003" /*Iceland*/
replace preparty5=0 if !inlist(B3018_1, 1,4,8) & !missing(preparty5) & preparty5!=200 & cntelec=="ISL_2003" 
tab preparty5 if cntelec=="ISL_2003"
tab B3018_1 if cntelec=="ISL_2003"

replace preparty5=2 if inlist(B3018_1, 4) & cntelec=="IRL_2002" /*Ireland*/
replace preparty5=10 if inlist(B3018_1, 3) & cntelec=="IRL_2002" /*Ireland*/
replace preparty5=11 if inlist(B3018_1, 6) & cntelec=="IRL_2002" /*Ireland*/
replace preparty5=0 if !inlist(B3018_1, 3,4,6) & !missing(preparty5) & preparty5!=200 & cntelec=="IRL_2002" 
tab preparty5 if cntelec=="IRL_2002"
tab B3018_1 if cntelec=="IRL_2002"

replace preparty5=3 if inlist(B3018_1, 9) & cntelec=="NLD_2002" /*Netherlands*/
replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="NLD_2002" /*Netherlands*/
replace preparty5=10 if inlist(B3018_1, 5) & cntelec=="NLD_2002" /*Netherlands*/
replace preparty5=11 if inlist(B3018_1, 10) & cntelec=="NLD_2002" /*Netherlands*/
replace preparty5=0 if !inlist(B3018_1, 1,5,10,9) & !missing(preparty5) & preparty5!=200 & cntelec=="NLD_2002" 
tab preparty5 if cntelec=="NLD_2002"
tab B3018_1 if cntelec=="NLD_2002"

replace preparty5=3 if inlist(B3018_1, 3) & cntelec=="NZL_2002" /*New Zealand*/
replace preparty5=2 if inlist(B3018_1, 1) & cntelec=="NZL_2002" /*New Zealand*/
replace preparty5=10 if inlist(B3018_1, 5) & cntelec=="NZL_2002" /*New Zealand*/
replace preparty5=11 if inlist(B3018_1, 7,8) & cntelec=="NZL_2002" /*New Zealand*/
replace preparty5=0 if !inlist(B3018_1, 1,5,7,8,3) & !missing(preparty5) & preparty5!=200 & cntelec=="NZL_2002" 
tab preparty5 if cntelec=="NZL_2002"
tab B3018_1 if cntelec=="NZL_2002"

replace preparty5=3 if inlist(B3018_1, 9) & cntelec=="NOR_2001" /*Norway*/
replace preparty5=2 if inlist(B3018_1, 3) & cntelec=="NOR_2001" /*Norway*/
replace preparty5=10 if inlist(B3018_1, 1) & cntelec=="NOR_2001" /*Norway*/
replace preparty5=11 if inlist(B3018_1, 2) & cntelec=="NOR_2001" /*Norway*/
replace preparty5=0 if !inlist(B3018_1, 1,2,3,9) & !missing(preparty5) & preparty5!=200 & cntelec=="NOR_2001" 
tab preparty5 if cntelec=="NOR_2001"
tab B3018_1 if cntelec=="NOR_2001"

replace preparty5=2 if inlist(B3018_1, 2) & cntelec=="ESP_2004" /*Spain*/
replace preparty5=10 if inlist(B3018_1, 15,18) & cntelec=="ESP_2004" /*Spain*/
replace preparty5=11 if inlist(B3018_1, 3) & cntelec=="ESP_2004" /*Spain*/
replace preparty5=0 if !inlist(B3018_1, 2,3,15,18) & !missing(preparty5) & preparty5!=200 & cntelec=="ESP_2004" 
tab preparty5 if cntelec=="ESP_2004"
tab B3018_1 if cntelec=="ESP_2004"

replace preparty5=2 if inlist(B3018_1, 2) & cntelec=="SWE_2002" /*Sweden*/
replace preparty5=10 if inlist(B3018_1, 7) & cntelec=="SWE_2002" /*Sweden*/
replace preparty5=11 if inlist(B3018_1, 1) & cntelec=="SWE_2002" /*Sweden*/
replace preparty5=0 if !inlist(B3018_1, 1,2,7) & !missing(preparty5) & preparty5!=200 & cntelec=="SWE_2002" 
tab preparty5 if cntelec=="SWE_2002"
tab B3018_1 if cntelec=="SWE_2002"

label var preparty5 "preparty choice, detailed"
lab def preparty5 0"Non-Left" 2"Social democrats" 3"Populists" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5 preparty5
tab preparty5

* 4.2 Pre-Turnout

tab B3016
recode B3016 1=1 2=2 4/5=3 7/9=3 6=4, gen (preturnout)
label var preturnout "Pre-Turnout" 
lab def preturnout 1 "Voted" 2 "Not voted" 3 "Other" 4"Not eligible"
lab val preturnout preturnout
tab preturnout


* 4.3 Merge preparty and preturnout: new variable preparty5abs

gen preparty5abs=preparty5
replace preparty5abs=4 if preturnout==2 /*turnout: add a fourth category*/ 
replace preparty5abs=5 if preturnout==4 /*not eligible: add a fifth category*/ 
replace preparty5abs=6 if preturnout==3 /*other answer on turnout: add a sixth category*/ 
label var preparty5abs "preparty choice with abstainers, detailed"
lab def preparty5abs 0"Non-Left" 2"Social democrats" 3"Populists" 4"Not voting" 5"Not eligible" 6"Other turnout" 10"Greens and others" 11"Radical Left" 200 "Other pc"
lab val preparty5abs preparty5abs
tab preparty5abs


*-------------------------------------------------------------------------------
* 5. Finalize the data set 
*-------------------------------------------------------------------------------

keep cntry cntelec unionm age gender locat educ clasdtprep status clasdt party5 turnout party5abs preparty5 preturnout preparty5abs

save cses2_rec, replace 
